package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Zixishileixing;
import com.example.exception.CustomException;
import com.example.service.ZixishileixingService;
import com.example.vo.ZixishileixingVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("zixishileixingService")
public class ZixishileixingServiceImpl extends ServiceImpl<ZixishileixingDao, Zixishileixing> implements ZixishileixingService {

    @Resource
    private ZixishileixingDao zixishileixingDao;

    public Zixishileixing add(Zixishileixing zixishileixing) {
		
	   //youquchong1
        zixishileixing.setAddtime(new Date());
        zixishileixingDao.insert(zixishileixing);
        return zixishileixing;
    }
	
	
	
    public void delete(Long id) {
        zixishileixingDao.deleteById(id);
    }
	

    public void update(Zixishileixing zixishileixing) {
        //youquchong2
        zixishileixingDao.updateById(zixishileixing);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return zixishileixingDao.daochuexcel();
    }

    @Override
    public Zixishileixing findById(Integer id) {
        return zixishileixingDao.selectById(id);
    }

    public ZixishileixingVo findPage(ZixishileixingVo zixishileixingVo) {
        LambdaQueryWrapper<Zixishileixing> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(zixishileixingVo.getLeixing()), Zixishileixing::getLeixing,zixishileixingVo.getLeixing());        wrapper.like(ObjectUtils.isNotEmpty(zixishileixingVo.getBeizhu()), Zixishileixing::getBeizhu,zixishileixingVo.getBeizhu());        
        Page<Zixishileixing> page = new Page<>(zixishileixingVo.getCurrent(),zixishileixingVo.getCurrentNum());
        zixishileixingDao.selectPage(page,wrapper);
        List<Zixishileixing> zixishileixings = page.getRecords();
        zixishileixingVo.setList(zixishileixings);
        zixishileixingVo.setPages(page.getPages());
        zixishileixingVo.setTotal(page.getTotal());
        zixishileixingVo.setCurrent(page.getCurrent());
        zixishileixingVo.setCurrentNum(page.getSize());
        return zixishileixingVo;
    }

    @Override
    public void deleteList(List<Zixishileixing> list) {
        List<Integer> ids =  list.stream().map(Zixishileixing::getId).collect(Collectors.toList());
        zixishileixingDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
